package cn.buk.api.ctrip.Factory;

import cn.buk.util.DateUtil;
import ctrip.api.flight.trade.common.basetype.v1.*;
import ctrip.api.flight.trade.message.specialpolicy.v1.*;

import java.math.BigDecimal;

/**
 * Created by yfdai on 15/11/27.
 */
public class CtripQuickApiFactory {
    public static SpecialPolicyDetailType createCtripSpecialPolicyDetailType() {
        SpecialPolicyDetailType policy = new SpecialPolicyDetailType();
        policy.setSummaryUnit(new SpecialPolicySummaryType());
        policy.setRuleRestrict(new RuleRestrictType());
        policy.setInventoryUnit(new SpecialPolicyInventoryType());
        policy.setGoFlightUnit(new SpecialPolicyFlightType());
        policy.setPriceUnit(new SpecialPolicyPriceType());
        policy.setTicketUnit(new SpecialPolicyTicketType());

        //产品类型
        policy.getSummaryUnit().setProductType(PolicyProductType.QW);
        //出票备注
        policy.getSummaryUnit().setTicketRemark("");
        //物理舱位
        policy.getSummaryUnit().setClazz(ServiceLevelType.Y);
        policy.getSummaryUnit().setDateCanSale(IsValidType.T);
        policy.getSummaryUnit().setEffectDate(DateUtil.convertDateToXMLGregorianCalendar(DateUtil.createDate(2015, 1, 1)));
        policy.getSummaryUnit().setExpiryDate(DateUtil.convertDateToXMLGregorianCalendar(DateUtil.createDate(2016,12,30)));
        policy.getSummaryUnit().setSaleTimeLimit("");

        policy.getSummaryUnit().setIsAutoTicket(IsValidType.F);
        policy.getSummaryUnit().setApplyFlag(ApplyFlagType.NA);
        policy.getSummaryUnit().setNeedPATA(IsValidType.F);
        //验价基准
        policy.getSummaryUnit().setPataBasePrice(10);
        policy.getSummaryUnit().setDownFloatValue(1);
        policy.getSummaryUnit().setIsShareFlight(IsValidType.F);

        policy.getSummaryUnit().setApplyChild(IsValidType.F);


        //是否可售
        policy.getGoFlightUnit().setIsCanSale(IsValidType.T);
        policy.getGoFlightUnit().setRuleDetail("");
        policy.getGoFlightUnit().setEffectDate(DateUtil.convertDateToXMLGregorianCalendar(DateUtil.createDate(2015, 1, 1)));
        policy.getGoFlightUnit().setExpiryDate(DateUtil.convertDateToXMLGregorianCalendar(DateUtil.createDate(2016,12,30)));
        policy.getGoFlightUnit().setDepartTimeLimit("");
        policy.getGoFlightUnit().setDays("1234567");

        //退票计算基准,F-标准价
        policy.getRuleRestrict().setFeeBasis(FeeBasisType.F);
        //退票手续费率
        policy.getRuleRestrict().setRefundRateRemarks("100-0-100");
        policy.getRuleRestrict().setMinFeeExpense(BigDecimal.valueOf(500));
        //改期手续费率
        policy.getRuleRestrict().setReroutRateRemarks("100-0-100");
        policy.getRuleRestrict().setIsEndorse(IsValidType.F);

        //库存类型
        policy.getInventoryUnit().setInventoryType(InventoryTypeType.FAV);
        policy.getInventoryUnit().setIsBooking(IsValidType.T);


        return policy;
    }

    public static SpecialPolicyDetailType copySpecialPolicyDetail(SpecialPolicyDetailType s0) {
        SpecialPolicyDetailType s1 = createCtripSpecialPolicyDetailType();

        s1.getSummaryUnit().setClazz(s0.getSummaryUnit().getClazz());

        s1.getSummaryUnit().setFlightWay(s0.getSummaryUnit().getFlightWay());
        s1.getSummaryUnit().setIsValid(s0.getSummaryUnit().getIsValid());

        s1.getSummaryUnit().setPolicyCode(s0.getSummaryUnit().getPolicyCode());
        s1.getSummaryUnit().setAirLine(s0.getSummaryUnit().getAirLine());

        s1.getSummaryUnit().setDepartPort(s0.getSummaryUnit().getDepartPort());
        s1.getSummaryUnit().setArrivePort(s0.getSummaryUnit().getArrivePort());

        s1.getSummaryUnit().setAdvanceDay(s0.getSummaryUnit().getAdvanceDay());
        s1.getSummaryUnit().setMaxAdvanceDay(s0.getSummaryUnit().getMaxAdvanceDay());

        s1.getSummaryUnit().setOfficeNo(s0.getSummaryUnit().getOfficeNo());

        s1.getGoFlightUnit().setSubClass(s0.getGoFlightUnit().getSubClass());
        s1.getGoFlightUnit().setEffectDate(s0.getGoFlightUnit().getEffectDate());
        s1.getGoFlightUnit().setExpiryDate(s0.getGoFlightUnit().getExpiryDate());


        s1.getPriceUnit().setPrintPrice(s0.getPriceUnit().getPrintPrice());
        s1.getPriceUnit().setReturnPoint(s0.getPriceUnit().getReturnPoint());
        s1.getPriceUnit().setReturnPrice(s0.getPriceUnit().getReturnPrice());

        return s1;
    }
}
